package com.member.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.member.exception.CustomException;
import com.member.po.StudentMessage;
import com.member.service.StudentMessageService;

@Controller
@RequestMapping("/studentMessage")
public class StudentMessageController {
	
   @Autowired
   private StudentMessageService studentMessageService;
	
	@RequestMapping("/studentMessage")
	public String studentMessage(HttpServletRequest request,Model model){
		//System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
	    String name = request.getParameter("name");
	    //System.out.println(name);
		if(name != null){
			StudentMessage studentMessage = studentMessageService.selectByName(name);
			model.addAttribute("studentMessage", studentMessage);
		}
		
		return "/baseInfo/studentMessage/studentMessage";
	}
	
	@RequestMapping("/editStudentMessage")
	public String editStudentMessage(Model model,@RequestParam(value = "id", required = true) Integer items_id) throws CustomException{
		StudentMessage studentMessage = studentMessageService.selectById(items_id);
		if(studentMessage == null){
			throw new CustomException("修改的班级信息不存在!");
		}
		model.addAttribute("items", studentMessage);
		return"baseInfo/studentMessage/studentMessageUpdate";
	}
	
	@RequestMapping("/deleteStudentMessage")
	public String deleteStudentMessage(@RequestParam(value="id")int id){
		studentMessageService.deleteById(id);
		return "redirect:/student/student";
	}
	
	@RequestMapping("/updateStudentMessageSubmit")
	public String updateStudentMessageSubmit(StudentMessage studentMessage){
		studentMessageService.updateById(studentMessage);
		return "redirect:/student/student";
	}
}
